import * as React from 'react';
import { Form, Divider } from 'antd';




import ITable from "../../components/ITable"
import IUserId from "../../components/IUserId"





const filter: any[] = [
  {
    type: "select",
    name: "type",
    label: "",
    items: [{
      key: "",
      value: "全部",
    }, {
      key: "AGREEMENT_FROM",
      value: "共识券转入",
    },
    {
      key: "AGREEMENT_TO",
      value: "共识券转出",
    },
    {
      key: "TOKEN_AGREEMENT",
      value: "购买共识券",
    },
    {
      key: "AVAILABLE_TOKEN",
      value: "可用-GW",
    },
    {
      key: "TOKEN_AVAILABLE",
      value: "GW-可用",
    },]
  },
];

const filterData = {
  type: "",
  itemType: "RMB"
};


const rowKey: string = "id";


let columns: any[] = [{
  title: "ID",
  dataIndex: "id",
}, {
  title: "时间",
  width: 320,
  dataIndex: "createTime",
}, {
  title: "会员账号",
  dataIndex: "userId",
  render: (text: any, record: any) => {
    return <IUserId id={text} />
  }
}, {
  title: "数量",
  dataIndex: "quantity",
}, {
  title: "详情",
  width: 240,
  render: (text: any, record: any) => {
    switch (record.type) {
      case "共识券转入":
        return <>来做于：{record.tip}</>;
      case "AGREEMENT_TO":
        return <>转至：{record.tip}</>;
      default:
        const data = record.tip.split(",");
        const status: any = {
          token(value: string) {
            return `花费GW:${(parseFloat(value) / 100000000).toFixed(4)}`;
          },
          gswCny(value: string) {
            return `GW行情:${(parseFloat(value) / 10000).toFixed(2)}`
          }
        }
        return <>{
          data.map((item: any) => {
            const itemData: string[] = item.split(":");
            const statu = status[itemData[0]];
            return <p key={itemData[0]}>
              {statu(itemData[1])}
            </p>
          })
        }</>
    }
  }
}, {
  title: "类型",
  render: (text: any, record: any) => {
    const status: any = {
      AGREEMENT_FROM: "共识券转入",
      AGREEMENT_TO: "共识券转出",
      TOKEN_AGREEMENT: "购买共识券",
      AVAILABLE_TOKEN: "可用转至GW",
      TOKEN_AVAILABLE: "GW转至可用",
    }
    return <>{status[record.type]}</>
  }
}];

const ITButton: React.FC = () => {
  return <>
    {/* <IExport url="/admin/wallet/export" /> */}
  </>
}

class List extends React.Component<{
  history: any,
  form: any,
}> {

  state = {
    url: "",
  }

  componentDidMount() {
    const params = new URLSearchParams(this.props.history.location.search);
    const id = params.get("id");
    this.setState({
      url: `/admin/accounts/${id}/logs`
    })
  }


  public render() {
    return !!this.state.url ? <ITable
      {...this.props}
      ITButton={ITButton}
      url={this.state.url}
      filter={filter}
      filterData={filterData}
      columns={columns}
      rowKey={rowKey}
    /> : null;

  }
}






export default Form.create({ name: 'List' })(List);




